<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Classify from "./../classify/index";
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {
    SelectImageRadio: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImageRadio()),
    SelectImageCheckbox: async () =>
      Vue.extend(
        await Vue.prototype.$vFN.Components.Base.SelectImageCheckbox()
      ),
    SelectGoods: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectGoods()),
    SelectDateCycleApplication: async () =>
      Vue.extend(
        await Vue.prototype.$vFN.Components.Base.SelectDateCycleApplication()
      ),
    SelectAddressMap: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectAddressMap()),
    SelectDataUsers: async () =>
      Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectDataUsers()),
  },
  data() {
    return {
      appWindow: window,
      form: {
        // 会员ID
        member_id: "",
        // 店长姓名
        manage: "",
        // 店长手机号
        mobile: "",
        // 门店名称
        name: "",
        // 分类ID
        category_id: "",

        // 省ID
        province_id: "",
        // 省名称
        province: "",
        // 市ID
        city_id: "",
        // 市名称
        city: "",
        // 地区ID
        district_id: "",
        // 地区名称
        district: "",
        // 详细地址
        address: "",

        // 经度
        longitude: "",
        // 纬度
        latitude: "",

        // 营业执照图片地址
        license_img: "",
        // 身份证正面图片
        id_card_front_img: "",
        // 身份证反面图片
        id_card_back_img: "",
        // logo图片地址
        logo_img: "",
        // 营业范围(Km)
        operate_scope: 5,
        // 营业状态0关闭1开启
        operate_status: 1,

        // 营业时间
        operate_list: [],
        // 开门时间
        // operate_open_time: "",
        // 关门时间
        // operate_close_time: "",

        // 过期类型1无限2有限期
        validity_type: 1,
        // 过期天数
        validity_days: "",
        // 有限期过期时间
        validity_end: "",

        // 是否可以线上快递1可以
        send_online: 1,
        // 是否可以线下自提1可以
        send_offline: 1,
        // 自提地址(其他地址)
        offline_address: "",
        // 提货地址类型1与本店地址相同
        offline_type: 1,

        // 结算比例
        cost_ratio: "0",
        // 结算天数
        cost_days: 0,
        // 门店首页网址(生成二维码)
        store_index_url: "",
        // 门店收银台网址(生成二维码)
        store_cashier_url: "",

        // 门店介绍
        content: "",
        // 门店分享标题
        share_title: "",
        // 门店分享图片
        share_img: "",
        image_list: [],
        // thumb_list: ["xx.jpg", "xx.jpg"],
        password: "",
        username: "",

        bg_img: "",
      },

      // 页面接口地址 admin/category/index
      apiUrl: {
        create: "admin/store/add",
        update: "admin/store/edit",
        detail: "admin/store/detail",
      },
      item: "",

      usersIds: [],
      
    };
  },
  methods: {
    // 选择门店分类
    async storeClass() {
      Classify.init({
        onSuccess: (res) => {
          console.log(res);
          this.item = res.name;
          this.form.category_id = res.id;
        },
      });
    },

    // 验证平台抽佣
    validatorNumber(rule, value, callback){

          // 0-100包含小数,限制两位
          if( parseFloat(value) > 100 ) {
             callback(new Error("最大100%"));
          }else{
               this.$vFN.Tools.validateMoney(rule, value, callback);
          }
    },

    // 选择分类相关
    async selectClass() {
      let res = await this.$vFN.Http.post(
        {
          url: "admin/category/select",
        },
        this.appWindow
      );
      // console.log(res.data.list);
      res.data.list.forEach((item) => {
        if (this.form.category_id == item.id) {
          this.item = item.name;
        }
      });
    },

    selectAddressMap() {
      this.$vFN.Directives.SelectAddressMap({
        appWindow: this.appWindow,
        onSuccess: (res) => {
          console.log(res, "1111111111111111");
          this.form.longitude = res.data.lat;
          this.form.latitude = res.data.lng;
          this.form.address = res.data.detailAddress;

          // cityCode provinceCode regionCode
          this.form.city_id = res.data.cityCode;
          this.form.province_id = res.data.provinceCode;
          this.form.district_id = res.data.regionCode;

          this.form.city = res.data.city;
          this.form.province = res.data.province;
          this.form.district = res.data.region;
        },
      });
    },

    // form 提交添加/修改 的参数扩展方法
    mixinEdit_editFormSubmitExtend(data_) {
      if (typeof data_.operate_list == "object") {
        data_.operate_list = JSON.stringify(data_.operate_list);
        data_.item = this.item;
      }
      data_.member_id = this.usersIds[0];
      return data_;
    },
    // 编辑修改的参数扩展方法
    mixinEdit_editDataExtend(data_) {
      // 添加
      if (this.mixinEdit_editType == "add") {
      }
      // 修改
      else if (this.mixinEdit_editType == "update") {
        console.log(this.usersIds, data_.member_id);
        this.usersIds = []
        this.usersIds.push(data_.member_id);

        if (typeof data_.operate_list == "string") {
          data_.operate_list = JSON.parse(data_.operate_list);
        }

        data_.username = data_.admin_username;

        // 密码默认为空
        data_.password = "";
       
      }
      return data_;
    },

    SelectGoods() {
      this.$vFN.Directives.SelectGoods({
        appWindow: this.appWindow,
        data: [],
        type: "classify",
        options: ["classify"],
        onSuccess: (res) => {
          // console.error(res.data, "111111111");
        },
      });
    },

    // 选择会员
    selectMembers() {
      this.$vFN.Directives.SelectDataUsers({
        appWindow: this.appWindow,
        selectIds: this.usersIds,
        apiConfig: this.$vFN.Tools.getAppGlobalData('componentsApiConfig.SelectDataUsers', this.appWindow),
        count: -1,
        onSuccess: (res) => {
        // 返回客户数组  因为只选一个 所以res[0]
        console.log(res, "res");
        this.form.member_id = res[0]
        // this.updateRelation(res[0]);
        },
      });
    },

    // 初始化
    async init() {
      // 初始化数据
      await this.mixinEdit_editBoxInit({
        model: "form",
        id: this.id,
      });
      // this.mixinTable_refreshData();
      // 显示窗口
      //   this.mixinEdit_editVisible = true;
      this.selectClass();
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>